﻿using EasyDDD.Domain;
using Microsoft.EntityFrameworkCore;

namespace EasyDDD.Infrastructure
{
    public interface IRepository<TEntiy>
        where TEntiy : IDomainEntity, IAggregateRoot
    {
        System.Linq.IQueryable<TEntiy> AsQueryable();

        TEntiy Add(TEntiy entity);
        Task<TEntiy> AddAsync(TEntiy entity, CancellationToken cancellationToken = default);
        TEntiy Update(TEntiy entity);
        Task<TEntiy> UpdateAsync(TEntiy entity, CancellationToken cancellationToken = default);
        bool Remove(TEntiy entity);
        Task<bool> RemoveAsync(TEntiy entity, CancellationToken cancellationToken = default);
    }

    public interface IRepository<TEntiy, TKey> : IRepository<TEntiy>
        where TEntiy : IDomainEntity<TKey>, IAggregateRoot
        //where TKey : IKey<TKey>
    {
        bool Remove(TKey Id);
        Task<bool> RemoveAsync(TKey Id, CancellationToken cancellationToken = default);

        TEntiy Get(TKey Id);
        TEntiy Get(TKey Id, Guid RowVersion);
        TEntiy? GetOrNull(TKey Id);
        TEntiy? GetOrNull(TKey Id, Guid RowVersion);

        Task<TEntiy> GetAsync(TKey Id, CancellationToken cancellationToken = default);
        Task<TEntiy> GetAsync(TKey Id, Guid RowVersion, CancellationToken cancellationToken = default);
        Task<TEntiy?> GetOrNullAsync(TKey Id, CancellationToken cancellationToken = default);
        Task<TEntiy?> GetOrNullAsync(TKey Id, Guid RowVersion, CancellationToken cancellationToken = default);
    }
}